package com.xlhj.dubbo.controller;

import com.xlhj.dubbo.api.service.UserApiService;
import com.xlhj.dubbo.api.vo.UserVo;
import com.xlhj.dubbo.common.ResultData;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: lcj
 * @Date: 2020/11/19 10:18
 * @Description: 用户信息控制器
 * @Version: 0.0.1
 */
@RestController
@RequestMapping("/user")
public class SysUserController {

    @DubboReference(version = "${consumer.service.version}")
    UserApiService userService;

    /**
     * 根据用户名和密码查询用户信息
     * @param username
     * @param password
     * @return
     */
    @ApiOperation(value = "根据用户ID查询用户信息")
    @PostMapping("/selectUserByUserNameAndPassword/{username}/{password}")
    public ResultData selectUserByUserNameAndPassword(@PathVariable String username, @PathVariable String password) {
        UserVo user = userService.selectUserByUserNameAndPassword(username, password);
        if (user != null) {
            return ResultData.ok().data("user", user);
        } else {
            return ResultData.error();
        }
    }
}
